{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "#coding:utf-8\n",
    "#导入warnings包，利用过滤器来实现忽略警告语句。\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import missingno as msno\n",
    "\n",
    "Train_data = df_train1 = pd.read_csv('data/train1.txt',sep='\\t')\n",
    "Test_data = df_test = pd.read_csv('data/test.txt',sep='\\t')\n",
    "df_submit = pd.read_csv('data/submit.txt',sep='\\t',header=None)\n",
    "df_train2 = pd.read_csv('data/train2.txt',sep='\\t',header=None)\n",
    "Train_data = Train_data[(Train_data['price'] < 700)]\n",
    "def split(data):\n",
    "    data['v12_0'] = data['v12'].apply(lambda x: x.split(\"*\")[0])\n",
    "    data['v12_1'] = data['v12'].apply(lambda x: x.split(\"*\")[1])\n",
    "    data['v12_2'] = data['v12'].apply(lambda x: x.split(\"*\")[2])\n",
    "    \n",
    "Test_data.loc[4102,'v12']=\"0*0*0\"\n",
    "split(Train_data)\n",
    "split(Test_data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "del Test_data['v15']\n",
    "del Test_data['v7']\n",
    "del Train_data['v7']\n",
    "del Train_data['v15']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pycaret.regression import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "                               Description             Value\n0                               session_id              2022\n1                                   Target             price\n2                            Original Data       (29999, 37)\n3                           Missing Values              True\n4                         Numeric Features                15\n5                     Categorical Features                18\n6                         Ordinal Features             False\n7                High Cardinality Features             False\n8                  High Cardinality Method              None\n9                    Transformed Train Set     (20999, 2200)\n10                    Transformed Test Set      (9000, 2200)\n11                      Shuffle Train-Test              True\n12                     Stratify Train-Test             False\n13                          Fold Generator             KFold\n14                             Fold Number                10\n15                                CPU Jobs                -1\n16                                 Use GPU              True\n17                          Log Experiment             False\n18                         Experiment Name  reg-default-name\n19                                     USI              067b\n20                         Imputation Type            simple\n21          Iterative Imputation Iteration              None\n22                         Numeric Imputer              mean\n23      Iterative Imputation Numeric Model              None\n24                     Categorical Imputer          constant\n25  Iterative Imputation Categorical Model              None\n26           Unknown Categoricals Handling    least_frequent\n27                               Normalize             False\n28                        Normalize Method              None\n29                          Transformation             False\n30                   Transformation Method              None\n31                                     PCA             False\n32                              PCA Method              None\n33                          PCA Components              None\n34                     Ignore Low Variance             False\n35                     Combine Rare Levels             False\n36                    Rare Level Threshold              None\n37                         Numeric Binning             False\n38                         Remove Outliers             False\n39                      Outliers Threshold              None\n40                Remove Multicollinearity             False\n41             Multicollinearity Threshold              None\n42             Remove Perfect Collinearity              True\n43                              Clustering             False\n44                    Clustering Iteration              None\n45                     Polynomial Features             False\n46                       Polynomial Degree              None\n47                    Trignometry Features             False\n48                    Polynomial Threshold              None\n49                          Group Features             False\n50                       Feature Selection             False\n51                Feature Selection Method           classic\n52            Features Selection Threshold              None\n53                     Feature Interaction             False\n54                           Feature Ratio             False\n55                   Interaction Threshold              None\n56                        Transform Target             False\n57                 Transform Target Method           box-cox",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Description</th>\n      <th>Value</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>session_id</td>\n      <td>2022</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Target</td>\n      <td>price</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Original Data</td>\n      <td>(29999, 37)</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Missing Values</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>Numeric Features</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Categorical Features</td>\n      <td>18</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Ordinal Features</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>High Cardinality Features</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>High Cardinality Method</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Transformed Train Set</td>\n      <td>(20999, 2200)</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>Transformed Test Set</td>\n      <td>(9000, 2200)</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>Shuffle Train-Test</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>Stratify Train-Test</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>Fold Generator</td>\n      <td>KFold</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>Fold Number</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>CPU Jobs</td>\n      <td>-1</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>Use GPU</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>Log Experiment</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>Experiment Name</td>\n      <td>reg-default-name</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>USI</td>\n      <td>067b</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>Imputation Type</td>\n      <td>simple</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>Iterative Imputation Iteration</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>Numeric Imputer</td>\n      <td>mean</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>Iterative Imputation Numeric Model</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>Categorical Imputer</td>\n      <td>constant</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>Iterative Imputation Categorical Model</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>Unknown Categoricals Handling</td>\n      <td>least_frequent</td>\n    </tr>\n    <tr>\n      <th>27</th>\n      <td>Normalize</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>28</th>\n      <td>Normalize Method</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>29</th>\n      <td>Transformation</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>30</th>\n      <td>Transformation Method</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>31</th>\n      <td>PCA</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>32</th>\n      <td>PCA Method</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>33</th>\n      <td>PCA Components</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>34</th>\n      <td>Ignore Low Variance</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>35</th>\n      <td>Combine Rare Levels</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>36</th>\n      <td>Rare Level Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>37</th>\n      <td>Numeric Binning</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>38</th>\n      <td>Remove Outliers</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>39</th>\n      <td>Outliers Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>40</th>\n      <td>Remove Multicollinearity</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>41</th>\n      <td>Multicollinearity Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>Remove Perfect Collinearity</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>Clustering</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>Clustering Iteration</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>Polynomial Features</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>Polynomial Degree</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>47</th>\n      <td>Trignometry Features</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>48</th>\n      <td>Polynomial Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>49</th>\n      <td>Group Features</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>50</th>\n      <td>Feature Selection</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>51</th>\n      <td>Feature Selection Method</td>\n      <td>classic</td>\n    </tr>\n    <tr>\n      <th>52</th>\n      <td>Features Selection Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>53</th>\n      <td>Feature Interaction</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>54</th>\n      <td>Feature Ratio</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>55</th>\n      <td>Interaction Threshold</td>\n      <td>None</td>\n    </tr>\n    <tr>\n      <th>56</th>\n      <td>Transform Target</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>57</th>\n      <td>Transform Target Method</td>\n      <td>box-cox</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {}
    }
   ],
   "source": [
    "exp_reg = setup(data = Train_data, target = 'price', session_id=2022,use_gpu = True) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "compare_models()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "         MAE       MSE     RMSE      R2   RMSLE    MAPE\n0     2.1378   24.8734   4.9873  0.8714  0.2730  0.2558\n1     2.4467  269.5540  16.4181  0.5331  0.2778  0.2470\n2     2.0678   16.5670   4.0703  0.9216  0.2723  0.2493\n3     2.1064   28.7014   5.3574  0.9041  0.2822  0.4299\n4     2.1829   30.6499   5.5362  0.8197  0.2803  0.2644\n5     2.2415   25.8065   5.0800  0.8615  0.2773  0.2628\n6     2.1800   42.5841   6.5256  0.8737  0.2839  0.2503\n7     2.0571   15.5981   3.9494  0.9354  0.2671  0.2482\n8     2.4578   82.4087   9.0779  0.8103  0.2651  0.2546\n9     2.1649   37.2206   6.1009  0.8773  0.2629  0.2397\nMean  2.2043   57.3964   6.7103  0.8408  0.2742  0.2702\nSD    0.1347   72.9874   3.5168  0.1092  0.0070  0.0537",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>MAE</th>\n      <th>MSE</th>\n      <th>RMSE</th>\n      <th>R2</th>\n      <th>RMSLE</th>\n      <th>MAPE</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2.1378</td>\n      <td>24.8734</td>\n      <td>4.9873</td>\n      <td>0.8714</td>\n      <td>0.2730</td>\n      <td>0.2558</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2.4467</td>\n      <td>269.5540</td>\n      <td>16.4181</td>\n      <td>0.5331</td>\n      <td>0.2778</td>\n      <td>0.2470</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2.0678</td>\n      <td>16.5670</td>\n      <td>4.0703</td>\n      <td>0.9216</td>\n      <td>0.2723</td>\n      <td>0.2493</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2.1064</td>\n      <td>28.7014</td>\n      <td>5.3574</td>\n      <td>0.9041</td>\n      <td>0.2822</td>\n      <td>0.4299</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2.1829</td>\n      <td>30.6499</td>\n      <td>5.5362</td>\n      <td>0.8197</td>\n      <td>0.2803</td>\n      <td>0.2644</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>2.2415</td>\n      <td>25.8065</td>\n      <td>5.0800</td>\n      <td>0.8615</td>\n      <td>0.2773</td>\n      <td>0.2628</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>2.1800</td>\n      <td>42.5841</td>\n      <td>6.5256</td>\n      <td>0.8737</td>\n      <td>0.2839</td>\n      <td>0.2503</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>2.0571</td>\n      <td>15.5981</td>\n      <td>3.9494</td>\n      <td>0.9354</td>\n      <td>0.2671</td>\n      <td>0.2482</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>2.4578</td>\n      <td>82.4087</td>\n      <td>9.0779</td>\n      <td>0.8103</td>\n      <td>0.2651</td>\n      <td>0.2546</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>2.1649</td>\n      <td>37.2206</td>\n      <td>6.1009</td>\n      <td>0.8773</td>\n      <td>0.2629</td>\n      <td>0.2397</td>\n    </tr>\n    <tr>\n      <th>Mean</th>\n      <td>2.2043</td>\n      <td>57.3964</td>\n      <td>6.7103</td>\n      <td>0.8408</td>\n      <td>0.2742</td>\n      <td>0.2702</td>\n    </tr>\n    <tr>\n      <th>SD</th>\n      <td>0.1347</td>\n      <td>72.9874</td>\n      <td>3.5168</td>\n      <td>0.1092</td>\n      <td>0.0070</td>\n      <td>0.0537</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {}
    }
   ],
   "source": [
    "ridge = create_model('ridge')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "         MAE       MSE     RMSE      R2   RMSLE    MAPE\n0     1.9445   22.7671   4.7715  0.8823  0.2551  0.2267\n1     2.2610  275.9913  16.6130  0.5219  0.2554  0.2167\n2     1.8676   13.7661   3.7103  0.9348  0.2496  0.2240\n3     1.9406   28.5330   5.3416  0.9047  0.2649  0.4029\n4     1.9829   25.7783   5.0772  0.8483  0.2589  0.2352\n5     2.0359   22.0307   4.6937  0.8817  0.2563  0.2331\n6     2.0089   45.5572   6.7496  0.8649  0.2583  0.2227\n7     1.8659   12.8361   3.5828  0.9469  0.2457  0.2194\n8     2.2785   86.9723   9.3259  0.7997  0.2516  0.2273\n9     1.9974   39.3606   6.2738  0.8703  0.2421  0.2073\nMean  2.0183   57.3593   6.6139  0.8456  0.2538  0.2415\nSD    0.1364   75.6940   3.6899  0.1150  0.0064  0.0543",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>MAE</th>\n      <th>MSE</th>\n      <th>RMSE</th>\n      <th>R2</th>\n      <th>RMSLE</th>\n      <th>MAPE</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.9445</td>\n      <td>22.7671</td>\n      <td>4.7715</td>\n      <td>0.8823</td>\n      <td>0.2551</td>\n      <td>0.2267</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2.2610</td>\n      <td>275.9913</td>\n      <td>16.6130</td>\n      <td>0.5219</td>\n      <td>0.2554</td>\n      <td>0.2167</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1.8676</td>\n      <td>13.7661</td>\n      <td>3.7103</td>\n      <td>0.9348</td>\n      <td>0.2496</td>\n      <td>0.2240</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1.9406</td>\n      <td>28.5330</td>\n      <td>5.3416</td>\n      <td>0.9047</td>\n      <td>0.2649</td>\n      <td>0.4029</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1.9829</td>\n      <td>25.7783</td>\n      <td>5.0772</td>\n      <td>0.8483</td>\n      <td>0.2589</td>\n      <td>0.2352</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>2.0359</td>\n      <td>22.0307</td>\n      <td>4.6937</td>\n      <td>0.8817</td>\n      <td>0.2563</td>\n      <td>0.2331</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>2.0089</td>\n      <td>45.5572</td>\n      <td>6.7496</td>\n      <td>0.8649</td>\n      <td>0.2583</td>\n      <td>0.2227</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>1.8659</td>\n      <td>12.8361</td>\n      <td>3.5828</td>\n      <td>0.9469</td>\n      <td>0.2457</td>\n      <td>0.2194</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>2.2785</td>\n      <td>86.9723</td>\n      <td>9.3259</td>\n      <td>0.7997</td>\n      <td>0.2516</td>\n      <td>0.2273</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>1.9974</td>\n      <td>39.3606</td>\n      <td>6.2738</td>\n      <td>0.8703</td>\n      <td>0.2421</td>\n      <td>0.2073</td>\n    </tr>\n    <tr>\n      <th>Mean</th>\n      <td>2.0183</td>\n      <td>57.3593</td>\n      <td>6.6139</td>\n      <td>0.8456</td>\n      <td>0.2538</td>\n      <td>0.2415</td>\n    </tr>\n    <tr>\n      <th>SD</th>\n      <td>0.1364</td>\n      <td>75.6940</td>\n      <td>3.6899</td>\n      <td>0.1150</td>\n      <td>0.0064</td>\n      <td>0.0543</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "              Model     MAE        MSE  RMSE      R2   RMSLE    MAPE\n0  Ridge Regression  1.8939  19.980801  4.47  0.9069  0.2486  0.2221",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Model</th>\n      <th>MAE</th>\n      <th>MSE</th>\n      <th>RMSE</th>\n      <th>R2</th>\n      <th>RMSLE</th>\n      <th>MAPE</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>Ridge Regression</td>\n      <td>1.8939</td>\n      <td>19.980801</td>\n      <td>4.47</td>\n      <td>0.9069</td>\n      <td>0.2486</td>\n      <td>0.2221</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Transformation Pipeline and Model Successfully Saved\n"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "(Pipeline(memory=None,\n",
       "          steps=[('dtypes',\n",
       "                  DataTypes_Auto_infer(categorical_features=[],\n",
       "                                       display_types=True, features_todrop=[],\n",
       "                                       id_columns=[], ml_usecase='regression',\n",
       "                                       numerical_features=[], target='price',\n",
       "                                       time_features=[])),\n",
       "                 ('imputer',\n",
       "                  Simple_Imputer(categorical_strategy='not_available',\n",
       "                                 fill_value_categorical=None,\n",
       "                                 fill_value_numerical=None,\n",
       "                                 numeric_strategy='...\n",
       "                 ('dummy', Dummify(target='price')),\n",
       "                 ('fix_perfect', Remove_100(target='price')),\n",
       "                 ('clean_names', Clean_Colum_Names()),\n",
       "                 ('feature_select', 'passthrough'), ('fix_multi', 'passthrough'),\n",
       "                 ('dfs', 'passthrough'), ('pca', 'passthrough'),\n",
       "                 ['trained_model',\n",
       "                  Ridge(alpha=0.44, copy_X=True, fit_intercept=True,\n",
       "                        max_iter=None, normalize=False, random_state=2022,\n",
       "                        solver='auto', tol=0.001)]],\n",
       "          verbose=False), 'Final Lightgbm Model 08Feb2020.pkl')"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "tuned_ridge = tune_model(ridge)\n",
    "predict_model(tuned_ridge)\n",
    "final_ridge = finalize_model(tuned_ridge)\n",
    "unseen_predictions = predict_model(final_ridge, data=Test_data)\n",
    "unseen_predictions.head()\n",
    "save_model(final_ridge,'Final ridge Model')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   cardid   tradeTime  brand  serial  model  ...  price  v12_0  v12_1  v12_2      Label\n",
       "0       3  2021-09-26      3       3      3  ...    NaN   4878   1925   1734  14.552002\n",
       "1       4  2021-08-14      4       4      4  ...    NaN   3723   1683   1407   9.542938\n",
       "2       8  2021-10-09      8       8      8  ...    NaN   4415   1674   1415   7.346497\n",
       "3       9  2021-09-30      9       9      9  ...    NaN   4649   1830   1705   6.817505\n",
       "4      11  2021-08-09      8      11     11  ...    NaN   4933   1836   1469  15.434784\n",
       "\n",
       "[5 rows x 38 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>cardid</th>\n      <th>tradeTime</th>\n      <th>brand</th>\n      <th>serial</th>\n      <th>model</th>\n      <th>mileage</th>\n      <th>color</th>\n      <th>cityId</th>\n      <th>carCode</th>\n      <th>transferCount</th>\n      <th>seatings</th>\n      <th>registerDate</th>\n      <th>licenseDate</th>\n      <th>country</th>\n      <th>maketype</th>\n      <th>modelyear</th>\n      <th>displacement</th>\n      <th>gearbox</th>\n      <th>oiltype</th>\n      <th>newprice</th>\n      <th>v1</th>\n      <th>v2</th>\n      <th>v3</th>\n      <th>v4</th>\n      <th>v5</th>\n      <th>v6</th>\n      <th>v8</th>\n      <th>v9</th>\n      <th>v10</th>\n      <th>v11</th>\n      <th>v12</th>\n      <th>v13</th>\n      <th>v14</th>\n      <th>price</th>\n      <th>v12_0</th>\n      <th>v12_1</th>\n      <th>v12_2</th>\n      <th>Label</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>3</td>\n      <td>2021-09-26</td>\n      <td>3</td>\n      <td>3</td>\n      <td>3</td>\n      <td>6.64</td>\n      <td>2</td>\n      <td>3</td>\n      <td>1</td>\n      <td>0</td>\n      <td>7</td>\n      <td>2018-03-01</td>\n      <td>2018-08-20</td>\n      <td>779416.0</td>\n      <td>2.0</td>\n      <td>2018.0</td>\n      <td>2.0</td>\n      <td>3</td>\n      <td>1</td>\n      <td>25.98</td>\n      <td>1.0</td>\n      <td>3</td>\n      <td>2</td>\n      <td>3.0</td>\n      <td>3</td>\n      <td>1</td>\n      <td>2.0</td>\n      <td>5.0</td>\n      <td>2.0</td>\n      <td>1+2</td>\n      <td>4878*1925*1734</td>\n      <td>201710.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>4878</td>\n      <td>1925</td>\n      <td>1734</td>\n      <td>14.552002</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>4</td>\n      <td>2021-08-14</td>\n      <td>4</td>\n      <td>4</td>\n      <td>4</td>\n      <td>8.04</td>\n      <td>3</td>\n      <td>1</td>\n      <td>2</td>\n      <td>2</td>\n      <td>4</td>\n      <td>2012-11-01</td>\n      <td>2013-04-20</td>\n      <td>779411.0</td>\n      <td>3.0</td>\n      <td>2011.0</td>\n      <td>1.6</td>\n      <td>3</td>\n      <td>1</td>\n      <td>26.90</td>\n      <td>1.0</td>\n      <td>4</td>\n      <td>2</td>\n      <td>4.0</td>\n      <td>4</td>\n      <td>3</td>\n      <td>1.0</td>\n      <td>3.0</td>\n      <td>2.0</td>\n      <td>1+2</td>\n      <td>3723*1683*1407</td>\n      <td>201010.0</td>\n      <td>2</td>\n      <td>NaN</td>\n      <td>3723</td>\n      <td>1683</td>\n      <td>1407</td>\n      <td>9.542938</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>8</td>\n      <td>2021-10-09</td>\n      <td>8</td>\n      <td>8</td>\n      <td>8</td>\n      <td>10.19</td>\n      <td>5</td>\n      <td>1</td>\n      <td>2</td>\n      <td>0</td>\n      <td>5</td>\n      <td>2012-08-01</td>\n      <td>2012-09-12</td>\n      <td>779412.0</td>\n      <td>2.0</td>\n      <td>NaN</td>\n      <td>1.6</td>\n      <td>6</td>\n      <td>1</td>\n      <td>7.58</td>\n      <td>1.0</td>\n      <td>2</td>\n      <td>2</td>\n      <td>NaN</td>\n      <td>8</td>\n      <td>2</td>\n      <td>1.0</td>\n      <td>4.0</td>\n      <td>3.0</td>\n      <td>NaN</td>\n      <td>4415*1674*1415</td>\n      <td>201003.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>4415</td>\n      <td>1674</td>\n      <td>1415</td>\n      <td>7.346497</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>9</td>\n      <td>2021-09-30</td>\n      <td>9</td>\n      <td>9</td>\n      <td>9</td>\n      <td>2.27</td>\n      <td>2</td>\n      <td>2</td>\n      <td>4</td>\n      <td>0</td>\n      <td>5</td>\n      <td>2019-12-01</td>\n      <td>2020-05-19</td>\n      <td>779413.0</td>\n      <td>1.0</td>\n      <td>2019.0</td>\n      <td>1.5</td>\n      <td>7</td>\n      <td>1</td>\n      <td>8.20</td>\n      <td>1.0</td>\n      <td>5</td>\n      <td>2</td>\n      <td>9.0</td>\n      <td>9</td>\n      <td>1</td>\n      <td>2.0</td>\n      <td>5.0</td>\n      <td>NaN</td>\n      <td>1+2</td>\n      <td>4649*1830*1705</td>\n      <td>201907.0</td>\n      <td>2</td>\n      <td>NaN</td>\n      <td>4649</td>\n      <td>1830</td>\n      <td>1705</td>\n      <td>6.817505</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>11</td>\n      <td>2021-08-09</td>\n      <td>8</td>\n      <td>11</td>\n      <td>11</td>\n      <td>7.03</td>\n      <td>2</td>\n      <td>3</td>\n      <td>1</td>\n      <td>0</td>\n      <td>5</td>\n      <td>2018-11-01</td>\n      <td>2019-03-08</td>\n      <td>779412.0</td>\n      <td>2.0</td>\n      <td>2019.0</td>\n      <td>2.0</td>\n      <td>7</td>\n      <td>1</td>\n      <td>21.79</td>\n      <td>1.0</td>\n      <td>6</td>\n      <td>2</td>\n      <td>11.0</td>\n      <td>10</td>\n      <td>2</td>\n      <td>2.0</td>\n      <td>4.0</td>\n      <td>NaN</td>\n      <td>1+2</td>\n      <td>4933*1836*1469</td>\n      <td>201810.0</td>\n      <td>1</td>\n      <td>NaN</td>\n      <td>4933</td>\n      <td>1836</td>\n      <td>1469</td>\n      <td>15.434784</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "unseen_predictions.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "unseen_predictions[['cardid','Label']].to_csv('submit.txt',header =None,index=None)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "a4a9b591a5d8c15248c8dae710090e12d42714cfc3a769cf18774ca735c05456"
  },
  "kernelspec": {
   "name": "python3712jvsc74a57bd04cd7ab41f5fca4b9b44701077e38c5ffd31fe66a6cab21e0214b68d958d0e462",
   "display_name": "Python 3.7.12 64-bit"
  },
  "language_info": {
   "name": "python",
   "version": "3.7.12"
  },
  "orig_nbformat": 4,
  "metadata": {
   "interpreter": {
    "hash": "4cd7ab41f5fca4b9b44701077e38c5ffd31fe66a6cab21e0214b68d958d0e462"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}